package com.amit.servlet;



import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

public class ForgotPWAction  extends JLCBaseAction{

	@Override
	public String service(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		Logger log=Logger.getLogger(ForgotPWAction.class);
		String result="forgotpw.jsp";
		log.info("ForgotPwAction-service()");
		
		String em=request.getParameter("email");
		log.info("Email:"+em);
		if(JLCValidator.validateRequired(em))
		{
		request.setAttribute("MSG", "Email is Required");
		
		return result;
		}
		else if(JLCValidator.validateEmail(em))
		{
		request.setAttribute("MSG", "Provide valid Email");
		return result;	
		}
		
		String pw=userService.getPasswordByEmail(em);
		if(pw!=null)
		{
			result="pwstatus.jsp";
			String sub="Your Password Here!";
			String body="<h1>Hi Your Password is "+pw+"</h1>";
			MailService.sendMail(em, sub, body);
		}
		
		else
		{
			request.setAttribute("MSG", "Email is not registered-try Again");
			log.info("Result:"+result);
			return result;
		}
		return result;
		
		
	}
	

}
